#include "MenuState.h"
#include "Game.h"
#include "TextureManager.h"
#include "MenuButton.h"
#include "PlayState.h"
#include "AnimatedGraphic.h"
#include "Defines.h"
#include "InputHandler.h"

const std::string MenuState::MenuID = "MENU";

void MenuState::Update()
{
	for(int i = 0; i < mGameObjects.size(); i++)
	{		
		mGameObjects[i]->Update();
	}
}

void MenuState::Draw()
{
	for(int i = 0; i < mGameObjects.size(); i++)
	{
		mGameObjects[i]->Draw();
	}
}

bool MenuState::OnEnter()
{
	if(!TextureManager::Instance()->Load(".\\assets\\button.png", "playbutton", Game::Instance()->getRenderer()))
		return false;

	if(!TextureManager::Instance()->Load(".\\assets\\exit.png", "exitbutton", Game::Instance()->getRenderer()))
		return false;

	if(!TextureManager::Instance()->Load(".\\assets\\gameover.png", "gameover", Game::Instance()->getRenderer()))
		return false;

	GameObject* button1 = new MenuButton(new LoadedParams((SCREEN_WIDTH / 2) - 200, 100, 400, 100, "playbutton"), menuToPlay);
	GameObject* button2 = new MenuButton(new LoadedParams((SCREEN_WIDTH / 2) - 200, 300, 400, 100, "exitbutton"), menuToExit);

	mGameObjects.push_back(button1);
	mGameObjects.push_back(button2);

	printf("Entering MenuState");
	return true;
}

bool MenuState::OnExit()
{
	for(int i = 0; i < mGameObjects.size(); ++i)
	{
		mGameObjects[i]->Shutdown();
	}
	mGameObjects.clear();
	TextureManager::Instance()->clearFromTextureMap("playbutton");
	TextureManager::Instance()->clearFromTextureMap("exitbutton");
	printf("Exiting MenuState\n");
	return true;
}

void MenuState::menuToPlay()
{
	Game::Instance()->getGameStateMachine()->changeState(new PlayState());
}

void MenuState::menuToExit()
{
	Game::Instance()->Shutdown();
}